package com.jason.game.online.home.view

import android.content.Context
import android.view.View
import com.cby.library.common.base.IViewSection
import com.cby.library.data.model.PosterBean
import com.cby.library.widget.GridLayout
import com.jason.game.online.R
import com.jason.game.online.home.adapter.GameHomePosterAdapter

/**
 * @description: HomePosterViewSection
 *
 * @author ChenBaoyang
 * @date 2021/10/27 09:57
 */
class HomePosterViewSection(context: Context) : IViewSection<List<PosterBean>>(context) {

    private lateinit var gridLayout: GridLayout
    private lateinit var adapter: GameHomePosterAdapter

    override fun populateView() {
        gridLayout = rootView.findViewById(R.id.grid_layout_poster)
        adapter = GameHomePosterAdapter(context)
        gridLayout.setAdapter(adapter)
        gridLayout.setOnItemClickListener { v, index ->

            //增加点击事件
            //H5ViewClickUtils.adJumpToPage(data.get(index).action)
            if (index !== 0) {
                adapter.setItemNewVisibility(v, View.GONE)
            }
        }
    }

    override fun getLayoutId() = R.layout.layout_header_poster

    override fun setData(data: List<PosterBean>) {
        adapter.setDatas(data)
    }

    fun setItemNewVisibility(visibility: Int) {
        adapter.setItemViewVisibility(0, visibility)
        adapter.notifyDataSetChanged()
    }
}